package com.bazaaroid.mobile.android.adapter;

import java.util.ArrayList;

import com.bazaaroid.mobile.android.R;
import com.bazaaroid.mobile.rest.model.partner.ActiveDiscountItem;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ActiveDiscountAdapter extends ArrayAdapter<ActiveDiscountItem> implements AdapterView.OnItemClickListener 
{
    private ArrayList<ActiveDiscountItem> items;

    public ActiveDiscountAdapter(Context context, int textViewResourceId, ArrayList<ActiveDiscountItem> items) 
    {
        super(context, textViewResourceId, items);
        this.items = items;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
    	View v = convertView;
    	if(v == null)
    	{
            LayoutInflater vi = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.products_row, null);
            
    	}
    	ActiveDiscountItem activeDiscount = items.get(position);
        if (activeDiscount != null) 
        {
                TextView tt = (TextView) v.findViewById(R.id.toptext);
                TextView bt = (TextView) v.findViewById(R.id.bottomtext);
                if (tt != null)
                      tt.setText("Name: " + activeDiscount.getProduct().getName());
                if (bt != null)
                      bt.setText("Desc: " + activeDiscount.getProduct().getDescription());
        }
		return v;
	}
    
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
    {
    	Dialog dialog = new Dialog(getContext());
    	dialog.setTitle(String.format("%d/%d", position, items.size()));
    }
}
